package com.gserver.utils.script;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.google.common.collect.Maps;

public class AIManager {
	public Map<String, Object> _bindings = Maps.newHashMap();

	public Map<Integer, AIObjectConfig> ais =  Maps.newHashMap();

	public AIManager() {
		_bindings.put("AIManager", this);
	}

	public void addAI(AIObjectConfig ai) throws Exception {
		if (ai != null) {
			if (ais.containsKey(ai.getId())) {
				throw new Exception("Duplicate AI ID:" + ai.getId());
			}
			ais.put(ai.getId(), ai);
		}
	}

	/**
	 * 创建一个AI对象
	 * 
	 * @return
	 */
	public AIObjectConfig createAI() {
		return new AIObjectConfig();
	}

	public class AIObjectConfig {
		/** AI Object的Id */
		private int id;

		/** AI生效的概率,默认是1.0,即100% */
		private float rate;

		/** 该AI拥有的规则 */
		private List<Integer> rules;

		public AIObjectConfig() {
			rules = new ArrayList<Integer>();
			rate = 1.0f;
		}

		public int getId() {
			return id;
		}

		public void setId(int id) {
			this.id = id;
		}

		public float getRate() {
			return rate;
		}

		public void setRate(float rate) {
			this.rate = rate;
		}

		public void addRule(int ruleId) {
			this.rules.add(ruleId);
		}

	}

}
